package com.kanasco.vision.controller;

import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import bb.access.po.Part;
import bb.access.po.Unit;
import bb.common.PartPK;
import com.kanasco.vision.service.IItemService;


public class SaveItemController extends SimpleFormController{
 
	IItemService itemServices;
	
	public IItemService getItemServices() {
		return itemServices;
	}
	public void setItemServices(IItemService itemServices) {
		this.itemServices = itemServices;
	}
	
	public SaveItemController() {
		setCommandClass(Part.class);
		setCommandName("item");
		
	}
	protected ModelAndView onSubmit(HttpServletRequest req,HttpServletResponse res,Object command,BindException exception) throws SQLException
  	{
	     String action=req.getParameter("action");
	     System.out.println("action from update"+action);
		 Part bean=(Part) command;
		 Part item=new Part();
		 PartPK pk=new  PartPK();
		 pk.setPartNumber(bean.getPk().getPartNumber());
		 pk.setPartType(bean.getPk().getPartType());
		 item.setPk(pk);
		 item.setRevision(bean.getRevision());
		 item.setDescription(bean.getDescription());
		 item.setPartUnit(bean.getPartUnit());
		 item.setOrigin("ADMIN");
		 item.setLastUser("Swapna");
		
		if(action.equalsIgnoreCase("saveItem")||action.equalsIgnoreCase("save"))
		{
			itemServices.createItem(item);

		}
		return new ModelAndView("UpdateItem","item",bean);
		

   }
}
